package com.itheima.common;

import lombok.Data;

@Data

public class CommonResult {

    private Integer code;

    private String msg;

    /**
     * 当接口是增删改的时候，这个data一般是返回一个成功或者失败的信息
     *
     * 当接口是查询的时候，这个data一般返回对象
     * 可以用泛型或者用Object
     */
    private Object data;

    public CommonResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static CommonResult success() {
        return new CommonResult(1, "成功", null);
    }

    public static CommonResult success(String msg) {
        return new CommonResult(1, msg, null);
    }
    public static CommonResult success(String msg,Object data) {
        return new CommonResult(1, msg, data);
    }

    public static CommonResult success(Object data) {
        return new CommonResult(1, "成功", data);
    }

    public static CommonResult error(String msg) {
        return new CommonResult(0, msg, null);
    }


}
